package com.dhsc.service.impl.xtqxgl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.ywzx.xtqxgl.KsmxVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.xtqxgl.IKsmxDao;
import com.dhsc.service.xtqxgl.IKsmxService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: KsmxServiceImpl
 * @Description: 用户考试明细
 * @date: 2023/11/3 16:30
 * @author: gx
 */
@Service
@Slf4j
public class KsmxServiceImpl implements IKsmxService {

    @Autowired
    private IKsmxDao ksmxDao;

    @Override
    public LayuiTableVo queryKsmx(KsmxVo ksmxVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(ksmxVo.getPage(), ksmxVo.getLimit());
            List<KsmxVo> list = ksmxDao.queryKsmx(ksmxVo);
            PageInfo<KsmxVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询用户考试明细信息出错",e);
            throw new MyException("查询用户考试明细信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryRyxm(KsmxVo ksmxVo) {
        ResponseObject obj = new ResponseObject();
        try {
            List<KsmxVo> list= ksmxDao.queryRyxm(ksmxVo);
            obj.setData(list);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("查询人员姓名信息出错", e);
            throw new MyException("查询人员姓名信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveKsmx(KsmxVo ksmxVo) {
        ResponseObject obj = new ResponseObject();
        try {
            ksmxDao.insertKsmx(ksmxVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("保存考试明细信息出错", e);
            throw new MyException("保存考试明细信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject deleteKsmx(KsmxVo ksmxVo) {
        ResponseObject obj = new ResponseObject();
        try {
            ksmxDao.deleteKsmx(ksmxVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("删除考试明细信息出错", e);
            throw new MyException("删除考试明细信息出错",e);
        }
        return obj;
    }
}
